package com.th.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.th.common.domain.UsSessionToken;
import com.th.common.domain.UsUser;
import com.th.common.domain.UsWalletInfo;

import com.th.common.domain.UsWalletTransaction;
import com.th.common.vo.UserInfoVo;
import com.th.common.vo.WalletInfoVo;
import com.th.mapper.UsWalletInfoMapper;

import com.th.service.UsSessionTokenService;
import com.th.service.UsUserService;
import com.th.service.UsWalletInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author 第五组
 * @Description TODO
 * @createTime 2023-06-24 16:54
 */
@Service
public class UsWalletInfoServiceImpl extends ServiceImpl<UsWalletInfoMapper, UsWalletInfo> implements UsWalletInfoService {

    @Resource
    private UsSessionTokenService usSessionTokenService;
    @Resource
    private UsUserService userService;
    @Resource
    private UsWalletInfoService usWalletInfoService;

    /***
     * 查询钱包信息
     * @return walletInfoVo
     */
    @Override
    public WalletInfoVo getWalletInfoVo() {
        Long userId = userService.getCurrentUserId();
        UsWalletInfo usWalletInfo = this.getBaseMapper().selectOne(UsWalletInfo::getUserId, userId);
        WalletInfoVo walletInfoVo = new WalletInfoVo();
        walletInfoVo.setBalance(usWalletInfo.getBalance());
        walletInfoVo.setTotalIncome(usWalletInfo.getTotalIncome());
        walletInfoVo.setTotalExpenditure(usWalletInfo.getTotalExpenditure());
        System.out.println(walletInfoVo);
        return walletInfoVo;
    }

    @Override
    public UsWalletInfo getWalletInfo() {
        Long userId = userService.getCurrentUserId();
        UsWalletInfo usWalletInfo = this.getBaseMapper().selectOne(UsWalletInfo::getUserId, userId);
        return usWalletInfo;
    }

}
